home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / boot / ConsoleFix.lha / ConsoleFix / ConsoleFix.asm < prev    next >
Assembly Source File  |  1999-01-07  |  6KB  |  207 lines

  1.         opt o+,ow-
  2. ;*************************************************
  3. ;** PatchConsole                                **
  4. ;** Patches a stupid bug in the console device  **
  5. ;*************************************************
  6.  
  7.         section main_code,code
  8.  
  9.         include inc:macros.asm
  10.         include inc:exec_lib.asm
  11.  
  12. PatchConsole:
  13.         move.l ExecBase,a6
  14.  
  15.         jsr Forbid(a6)
  16.  
  17.         lea $15e(a6),a0                 ;device list
  18.         lea ConsoleName(pc),a1
  19.         jsr FindName(a6)                ;don't try this stunt yourself
  20.         tst.l d0
  21.         beq .notpatched
  22.  
  23.         move.l d0,a0
  24.         move.w $14(a0),d1               ;get version
  25.         cmp.w #39,d1                    ;must be V39 or V40
  26.         beq.s .foundV39
  27.         cmp.w #40,d1                    ;or V40 ?
  28.         bne .notpatched
  29.  
  30. .foundV39:
  31.         lea ConsoleName(pc),a1
  32.         jsr FindTask(a6)                ;don't try this yourself
  33.         tst.l d0
  34.         beq .notpatched
  35.  
  36.         move.l d0,a4
  37.         move.w $e(a4),d0                ;get the state of the task
  38.         subq.w #$4,d0                   ;must be waiting
  39.         bne .notpatched
  40.  
  41.         move.l $36(a4),a1               ;get the stack pointer
  42.         move.l $3e(a4),a3               ;check up to this address
  43.         do
  44.          cmp.l a3,a1
  45.          bhs .notpatched
  46.          move.l (a1),a0                 ;read the return address
  47.          cmp.l #$f80004,a0              ;must be above this one
  48.          blo.s .next
  49.          cmp.l #$ffffff,a0              ;and below this one
  50.          bhi.s .next
  51.          move.l -4(a0),d0               ;read the instruction at this address
  52.          cmp.l #$4eaefec2,d0            ;must be Wait(a6)
  53.          bne.s .next
  54.  
  55.          move.w $3c(a0),d0              ;read first bsr.s
  56.          cmp.w #$6100,d0                ;long branch is not allowed
  57.          beq.s .next
  58.          and.w #$ff01,d0                ;mask out the jump distance
  59.          cmp.w #$6100,d0                ;must be bsr
  60.          bne.s .next
  61.  
  62.          move.w $5c(a0),d0              ;read first bsr.w
  63.          cmp.w #$6100,d0                ;must be bsr
  64.          bne.s .next
  65.  
  66.          move.w $82(a0),d0              ;read again instruction
  67.          cmp.w #$6100,d0                ;must be bsr.w again
  68.          beq.s .found                   ;if this matches, too, we got it.
  69. .next:
  70.          addq.l #2,a1                   ;next word
  71.         loop.s
  72. .found:
  73.         move.l a1,a4                    ;the return address is kept here
  74.  
  75.         lea $84(a0),a1                  ;get first extension word
  76.         move.w (a1),d0                  ;read jump distance
  77.         adda.w d0,a1                    ;the destination of the third jump
  78.         move.l a1,2+RomJump3            ;stunt! Patch in the code
  79.  
  80.         lea $5e(a0),a2
  81.         move.w (a2),d0
  82.         adda.w d0,a2
  83.         cmp.l a1,a2                     ;these two must go to the same address. Argh.
  84.         bne.s .notpatched
  85.         move.l a1,2+RomJump2
  86.  
  87.         lea $3c(a0),a1                  ;read first jump
  88.         move.w (a1)+,d0                 ;this is a short jump
  89.         and.w #$00ff,d0                 ;get the jump distance
  90.         beq.s .notpatched               ;if this is long, don't.
  91.         adda.w d0,a1                    ;calculate destination
  92.         move.l a1,2+RomJump1            ;destination
  93.  
  94.         move.l #WaitBack,(a4)           ;patch return address. Huh!
  95.                                         ;we're done now
  96.         jsr CacheClearU(a6)             ;done
  97.  
  98.         lea PatchConsole(pc),a0
  99.         clr.l -4(a0)                    ;release segment: Urghl.
  100.         moveq #0,d0                     ;Yes, I know this is ugly.
  101.         bra.s .exit
  102. .notpatched:
  103.         moveq #32,d0
  104. .exit:
  105.         jsr Permit(a6)                  ;does not alter the registers
  106.         rts
  107.  
  108. ConsoleName:
  109.         dc.b "console.device",0
  110.  
  111. ;*************************************************
  112. ;** The following is the replacement            **
  113. ;** code of the console.device                  **
  114. ;*************************************************
  115.  
  116.         section patched_code,code
  117.  
  118. PatchStart:
  119.  
  120. _loop:
  121.         move.b  $152(a6),d0
  122.         move.b  d0,d1
  123.         and.b   #$1C,d1
  124.         beq.s _release
  125.         btst    #7,d0
  126.         beq.s _release
  127.         bset    #5,d0
  128.         bne.s _release
  129.         move.b  d0,$152(a6)
  130.         move.l  $125A(a6),d0
  131.         beq.s _release
  132.         lea     $1246(a6),a1
  133.         move.w  #9,$1C(a1)
  134.         clr.b   $1E(a1)
  135.         moveq   #0,d1
  136.         move.l  d1,$20(a1)
  137.         move.l  #$186A0,$24(a1)
  138.         move.l  a6,-(a7)
  139.         movea.l d0,a6
  140.         jsr     -$1E(a6)
  141.         movea.l (a7)+,a6
  142. _release:
  143.         lea     $54(a6),a0
  144.         move.l  a6,-(a7)
  145.         movea.l $30(a6),a6
  146.         jsr     -$23A(a6)
  147.         movea.l (a7)+,a6
  148.         move.l  #$F0000000,d0
  149.         move.l  a6,-(a7)
  150.         movea.l $30(a6),a6
  151.         jsr     -$13E(a6)
  152. WaitBack:
  153.         movea.l (a7)+,a6
  154.         move.l  d0,d7
  155.         lea     $54(a6),a0
  156.         move.l  a6,-(a7)
  157.         movea.l $30(a6),a6
  158.         jsr     -$2A6(a6)
  159.         movea.l (a7)+,a6
  160.         tst.l   $50(a6)
  161.         beq _loop
  162.         move.l  d7,d0
  163.         andi.l  #$C0000000,d0
  164.         beq.s _test
  165.  
  166.         move.l  d7,-(a7)
  167.         lea     $126E(a6),a0
  168.         move.l  a6,-(a7)
  169.         movea.l $30(a6),a6
  170.         jsr     -$234(a6)
  171.         movea.l (a7)+,a6
  172.         lea     $82(a6),a2             ;this is the bug
  173.         bra.s _enterloop
  174. _windowloop:
  175.  
  176. RomJump1:
  177.         jsr $55555554                   
  178. _enterloop:
  179.         movea.l (a2),a2
  180.         tst.l   (a2)
  181.         bne.s _windowloop
  182.         lea     $126E(a6),a0
  183.         move.l  a6,-(a7)
  184.         movea.l $30(a6),a6
  185.         jsr     -$23A(a6)
  186.         movea.l (a7)+,a6
  187.         move.l  (a7)+,d7
  188. _test:
  189.         btst    #$1D,d7
  190.         beq.s _no1d
  191. RomJump2:
  192.         jsr $aaaaaaaa                   ;ditto
  193. _no1d:
  194.         btst    #$1C,d7
  195.         beq _loop
  196.         lea     $1224(a6),a0
  197.         move.l  a6,-(a7)
  198.         movea.l $30(a6),a6
  199.         jsr     -$174(a6)
  200.         movea.l (a7)+,a6
  201.         bclr    #5,$152(a6)
  202.         beq _loop
  203. RomJump3:
  204.         jsr $aaaaaaaa
  205.         beq _loop
  206.  
  207.